<!DOCTYPE html>
<html><head>
        <meta charset="utf-8">
    <title></title>

    <meta name="description" content="Dashboard">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--Basic Styles-->
    <link href="__ADMIN__/style/bootstrap.css" rel="stylesheet">
    <link href="__ADMIN__/style/font-awesome.css" rel="stylesheet">
    <link href="__ADMIN__/style/weather-icons.css" rel="stylesheet">

    <!--Beyond styles-->
    <link id="beyond-link" href="__ADMIN__/style/beyond.css" rel="stylesheet" type="text/css">
    <link href="__ADMIN__/style/demo.css" rel="stylesheet">
    <link href="__ADMIN__/style/typicons.css" rel="stylesheet">
    <link href="__ADMIN__/style/animate.css" rel="stylesheet">
    <script src="__PLUS__/ueditor/ueditor.config.js"></script>
    <script src="__PLUS__/ueditor/ueditor.all.min.js"></script>
    <script src="__PLUS__/ueditor/lang/zh-cn/zh-cn.js"></script>
    <style type="text/css">
    .price{
        width: 150px;
        margin-left: 10px;
        display: inline-block;
    }
    .abtn{
        padding-right: 10px;
    }
    </style>
</head>
<body>
    <!-- 头部 -->
    {include file="common/top"}
    <!-- /头部 -->
    
    <div class="main-container container-fluid">
        <div class="page-container">
            <!-- Page Sidebar -->
           <div class="page-sidebar" id="sidebar">
                <!-- Page Sidebar Header-->
                <div class="sidebar-header-wrapper">
                    <input class="searchinput" type="text">
                    <i class="searchicon fa fa-search"></i>
                    <div class="searchhelper">Search Reports, Charts, Emails or Notifications</div>
                </div>
                <!-- /Page Sidebar Header -->
                <!-- Sidebar Menu -->
               {include file="common/left"}
                <!-- /Sidebar Menu -->
            </div>
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                                        <li>
                        <a href="{:url('Index/index')}">系统</a>
                    </li>
                                        <li>
                        <a href="{:url('Goods/lists')}">商品列表</a>
                    </li>
                                        <li class="active">修改商品</li>
                                        </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">
                    
<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
                    <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
                        <input type="hidden" name="id" value="{$goods.id}">
                        <input type="hidden" name="og_thumb" value="{$goods.og_thumb}">
                        <input type="hidden" name="big_thumb" value="{$goods.big_thumb}">
                        <input type="hidden" name="mid_thumb" value="{$goods.mid_thumb}">
                        <input type="hidden" name="sm_thumb" value="{$goods.sm_thumb}">
                        <!-- 商品信息开始 -->
                        <div class="widget-body">
                            <div class="widget-main ">
                                <div class="tabbable">
                                    <ul class="nav nav-tabs tabs-flat" id="myTab11">
                                        <li class="active">
                                            <a data-toggle="tab" href="#baseinfo">
                                                基本信息
                                            </a>
                                        </li>
                                        <li class="">
                                            <a data-toggle="tab" href="#goodsdes">
                                                描述信息
                                            </a>
                                        </li>
                                        <li class="">
                                            <a data-toggle="tab" href="#mbprice">
                                                会员价格
                                            </a>
                                        </li>
                                        <li class="">
                                            <a data-toggle="tab" href="#goodsattr">
                                                商品属性
                                            </a>
                                        </li>
                                        <li class="">
                                            <a data-toggle="tab" href="#goodsphoto">
                                                商品相册
                                            </a>
                                        </li>
                                    </ul>
                                    <div class="tab-content tabs-flat">
                                        <div id="baseinfo" class="tab-pane active">
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">商品名称</label>
                                                <div class="col-sm-6">
                                                    <input class="form-control" placeholder="" name="goods_name" value="{$goods.goods_name}" required="" type="text">
                                                </div>
                                                <p class="help-block col-sm-4 red">* 必填</p>
                                            </div>
                                           <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">推荐位</label>
                                                <div class="col-sm-6">
                                                    <div class="checkbox">
                                                    {volist name="goodsRecposRes" id="recpos"}
                                                    <?php 
                                                    if(in_array($recpos['id'],$goodsItem)){
                                                        $select='checked="checked"';
                                                    }else{
                                                        $select='';
                                                    }
                                                    
                                                    ?>

                                                        <label style="margin-right:15px;">
                                                            <input <?php echo $select; ?> type="checkbox" name="recpos[]" value="{$recpos.id}" class="colored-blue">
                                                            <span class="text">{$recpos.rec_name}</span>
                                                        </label>
                                                    {/volist}
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">商品主图</label>
                                                <div class="col-sm-6">
                                                    <input class="form-control" style="border:none; box-shadow:none;" name="og_thumb" type="file">
                                                     {if condition="$goods['og_thumb'] neq ''"}
                                                     <img src="__UPLOADS__/{$goods['og_thumb']}" alt="" width="35">
                                                     {else}
                                                     暂无图片
                                                     {/if}
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">上架</label>
                                                <div class="col-sm-6">
                                                    <div class="radio">
                                                        <label>
                                                            <input {if condition="$goods['on_sale'] eq 1"}checked="checked"{/if}  name="on_sale" type="radio" class="colored-blue" value="1">
                                                            <span class="text"> 是</span>
                                                        </label>
                                                        <label>
                                                            <input {if condition="$goods['on_sale'] eq 0"}checked="checked"{/if} name="on_sale" type="radio" class="colored-blue" value="0">
                                                            <span class="text"> 否</span>
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">所属栏目</label>
                                                <div class="col-sm-6">
                                                    <select name="category_id">
                                                        <option value="">请选择</option>
                                                         {volist name="CategoryRes" id="cate"}
                                                        <option {if condition="$goods['category_id'] eq $cate['id']"}selected="selected"{/if} value="{$cate.id}"><?php echo str_repeat('-', $cate['level']*8)?>{$cate.cate_name}</option>
                                                        {/volist}
                                                       
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">所属品牌</label>
                                                <div class="col-sm-6">
                                                    <select name="brand_id">
                                                        <option value="">请选择</option>
                                                        {volist name="brandRes" id="brand"}
                                                        <option {if condition="$goods['brand_id'] eq $brand['id']"}selected="selected"{/if} value="{$brand.id}">{$brand.brand_name}</option>
                                                        {/volist}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">市场价</label>
                                                <div class="col-sm-6">
                                                    <input class="form-control" placeholder="" name="markte_price" value="{$goods.markte_price}" required="" type="text">
                                                </div>
                                                <p class="help-block col-sm-4 red">* 必填</p>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">本店价</label>
                                                <div class="col-sm-6">
                                                    <input class="form-control" placeholder="" name="shop_price" value="{$goods.shop_price}" required="" type="text">
                                                </div>
                                                <p class="help-block col-sm-4 red">* 必填</p>
                                            </div>
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">重量</label>
                                                <div class="col-sm-6">
                                                    <input class="form-control" style="width:300px; display:inline-block;" placeholder="" name="goods_weight" value="{$goods.goods_weight}" required="" type="text">
                                                    <select name="weight_unit">
                                                        <option {if condition="$goods['weight_unit'] eq 'kg'"}selected="selected"{/if} value="kg">kg</option>
                                                        <option {if condition="$goods['weight_unit'] eq 'g'"}selected="selected"{/if}  value="g">g</option>
                                                    </select>
                                                </div>
                                                <p class="help-block col-sm-4 red">* 必填</p>
                                            </div>
                                        </div>
                                        <div id="goodsdes" class="tab-pane">
                                            <textarea name="goods_des" id="goods_des">{$goods.goods_des}</textarea>
                                        </div>
                                        <div id="mbprice" class="tab-pane">
                                            {volist name="mlRes" id="vo"}
                                             <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">{$vo.level_name}</label>
                                                <div class="col-sm-3">
                                                    <input class="form-control" placeholder="" name="mp[{$vo.id}]" value="<?php if(isset($mpRes[$vo['id']]['mprice'])){echo $mpRes[$vo['id']]['mprice'];}else{echo '';} ?>" type="text">
                                                </div>
                                            </div>
                                            {/volist}
                                        </div>
                                        <div id="goodsattr" class="tab-pane">
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right">商品类型</label>
                                                <div class="col-sm-6">
                                                    <select name="type_id" disabled="disabled">
                                                        <option value="0">请选择</option>
                                                      {volist name="typeRes" id="type"}
                                                        <option {if condition="$goods['type_id'] eq $type['id']"}selected="selected"{/if} value="{$type.id}">{$type.type_name}</option>
                                                        {/volist}
                                                    </select>
                                                </div>
                                            </div>
                                            <div id="attr_list">
                                            <!-- 属性显示  -->
                                            <?php foreach($attrRes as $k=>$v):?>
                                                <?php if($v['attr_type']==1): $oldRes=explode(',', $v['attr_values']);?>
                                                    <!-- 单选 -->
                                                    <?php foreach($gattrRes[$v['id']] as $k0=>$v0):?>
                                                    <div gaid="<?php echo $v0['id'];?>" class="form-group"><label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name'];?></label><div class="col-sm-6"><a class="abtn" onclick="addrow(this);" href="#"><?php if($k0==0){echo '[+]';}else{echo '[-]';}?></a>
                                                  <select name='old_goods_attr[<?php echo $v['id'];?>][]'>
                                                    <option value="">请选择</option>
                                                     <?php foreach($oldRes as $k1=>$v1):?> 
                                                    <option <?php if($v1==$v0['attr_value'])echo 'selected="selected"';?>  value="<?php echo $v1;?>"><?php echo $v1;?></option>
                                                   <?php endforeach;?>
                                                  </select>
                                                  <input class="form-control price" placeholder="价格" name="old_attr_price[<?php echo $v0['id'];?>]" type="text" value="<?php echo $v0['attr_price']; ?>"></div></div>
                                                 <?php endforeach;?>
                                                <?php else:?>
                                                    <!-- 唯一 -->
                                                 <?php if(!$v['attr_values']):?> 
                                                <div gaid="" class="form-group"><label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name'];?></label><div class="col-sm-6"><a class="abtn" onclick="addrow(this);" href="#"></a>
                                                  <input class="form-control price" placeholder="价格" name="old_goods_attr[<?php echo $v['id'];?>]" type="text" value="<?php echo $gattrRes[$v['id']][0]['attr_value']?>"><input type="hidden" name="old_attr_price[<?php echo $gattrRes[$v['id']][0]['id'];?>]"></div></div>
                                                <?php else: $arrSelect=explode(',', $v['attr_values']);?>
                                                    <div class="form-group"><label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name'];?></label><div class="col-sm-6">
                                                        <select name='old_goods_attr[<?php echo $v['id'];?>]'>
                                                            <option value="">请选择</option>
                                                            <?php foreach($arrSelect as $k1=>$v1):?>
                                                            <option <?php if($v1 == $gattrRes[$v['id']][0]['attr_value']){ echo 'selected="selected"'; } ?> value="<?php echo $v1;?>"><?php echo $v1;?></option>
                                                            <?php endforeach;?>
                                                        </select>
                                                        <input type="hidden" name="old_attr_price[<?php echo $gattrRes[$v['id']][0]['id'];?>]">
                                                    </div></div>
                                                 <?php endif;?>   
                                                <?php endif;?>
                                            <?php endforeach;?>
                                            </div> 
                                        </div>
                                        <div id="goodsphoto" class="tab-pane">
                                        {volist name="gphotoRes" id="vo"}
                                            <div id="{$vo['id']}" class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right"></label>
                                                
                                                <div class="col-sm-6">
                                                    <a href="#" onclick="delrow(this);">[-]</a>
                                                    <img height="50" style="box-shadow:none; display:inline-block;" src="__UPLOADS__/{$vo['og_photo']}">
                                                </div>
                                               
                                            </div>
                                       {/volist}
                                            <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right"></label>
                                                <div class="col-sm-6">
                                                    <a href="#" onclick="addphoto(this);">[+]</a><input class="form-control" style="border:none; box-shadow:none; width:50%; display:inline-block;" name="goods_photo[]" type="file">
                                                </div>
                                            </div>
                                            <div id="goods_photo"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-default">保存信息</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- 商品信息结束 -->
                    </form>
        </div>
    </div>
</div>

                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
        </div>  
    </div>

        <!--Basic Scripts-->
    <script src="__ADMIN__/style/jquery_002.js"></script>
    <script src="__ADMIN__/style/bootstrap.js"></script>
    <script src="__ADMIN__/style/jquery.js"></script>
    <!--Beyond Scripts-->
    <script src="__ADMIN__/style/beyond.js"></script>
    <script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('goods_des',{initialFrameWidth:1500,initialFrameHeight:800,toolbars: [['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist','selectall', 'cleardoc']]});
    </script>
    <script type="text/javascript">
    $("select[name=type_id]").change(function(){
        var type_id=$(this).val();
        $.ajax({
            type:"POST",
            url:"{:url('Attr/ajaxGetAttr')}",
            data:{type_id:type_id},
            dataType:"json",
            success:function(data){
                // console.log(data);
                var html="";
                $(data).each(function(k,v){
                    if(v.attr_type == 1){
                        // 单选处理
                        html+="<div class='form-group'>";
                        html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                        var attrValuesArr=v.attr_values.split(",");
                        html+="<div class='col-sm-6'><a class='abtn' onclick='addrow(this);' href='#'>[+]</a>";
                        html+="<select name='goods_attr["+v.id+"][]'>";
                        html+="<option value=''>请选择</option>";
                        for(var i=0; i<attrValuesArr.length; i++){
                            html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                        }
                        html+="</select>";
                        html+="<input class='form-control price' placeholder='价格' name='attr_price[]' type='text'>";
                        html+="</div></div>";

                    }else{
                        // 唯一处理
                        if(v.attr_values){
                            html+="<div class='form-group'>";
                            html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                            var attrValuesArr=v.attr_values.split(",");
                            html+="<div class='col-sm-6'>";
                            html+="<select name=goods_attr["+v.id+"]>";
                            html+="<option value=''>请选择</option>";
                            for(var i=0; i<attrValuesArr.length; i++){
                                html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                            }
                            html+="</select>";
                            html+="</div></div>";
                        }else{
                            html+="<div class='form-group'>";
                            html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                            var attrValuesArr=v.attr_values.split(",");
                            html+="<div class='col-sm-6'>";
                            html+="<input class='form-control price' name=goods_attr["+v.id+"] type='text'>";
                            html+="</div></div>";
                        }
                    }
                });
                $("#attr_list").html(html);
            }
        });
    });
    
    function addrow(o){
        var div=$(o).parent().parent();
        if($(o).html() == '[+]'){
            var newdiv=div.clone();    
            newdiv.find('a').html('[-]');
            // 修改old_attr_price[]为attr_price[]
            newdiv.find(':text').attr('name','attr_price[]');
            // 修改old_goods_attr[8][]为goods_attr[8][]
            var sel=newdiv.find('select');
            var oldname=sel.attr('name');
            var newname=oldname.replace('old_','');
            sel.attr('name',newname);
            div.after(newdiv);
        }else{
            if(confirm('确定要删除该属性吗？')){
                var div=$(o).parent().parent();
                var gaid=div.attr('gaid');
                $.ajax({
                    type:"POST",
                    data:{gaid:gaid},
                    url:"{:url('GoodsAttr/ajaxdelga')}",
                    success:function(data){
                       if(data==1){
                            div.remove(); 
                        }else{
                            alert('删除失败！');
                        }
                    }
                });  
            }
        }
    }

    function addphoto(o){
        var div=$(o).parent().parent();
        if($(o).html() == '[+]'){
            var newdiv=div.clone();    
            newdiv.find('a').html('[-]');
            div.after(newdiv);
        }else{
            div.remove();
        }
    }

    function delrow(o){
        if(confirm('确定要删除该图吗？')){
            var div=$(o).parent().parent();
            var id=div.attr('id');
            $.ajax({
                type:"POST",
                data:{id:id},
                url:"{:url('Goods/ajaxdelpic')}",
                success:function(data){
                   if(data==1){
                        div.remove(); 
                    }else{
                        alert('删除失败！');
                    }
                }
            });  
        }
    }

    </script>

</body></html>